<?php

class SettingLogic
{
	// 缓存模型类
	private $_CacheModel = '';
	
	// 配置信息缓存前缀
	CONST INIT_CONFIG = 'INIT_CONFIG_LIST';
	
	public function __construct() {
		$this -> _CacheModel = D('Cache', 'Service');
		$this -> _CacheModel -> init();
	}
	
	/**
	 * 获取所有配置信息的值
	 * @return -2配置信息不存在，array配置信息
	 */
	public function getConfigList() {
		$key = self::INIT_CONFIG;
	
		$this -> _CacheModel -> rm($key);
		$configInfo = $this -> _CacheModel -> get($key);
		if (!$configInfo) {
			$configList = D('Config') -> select();
			if (!$configList)
				return -2;
				
			foreach ($configList as $config) {
				$configInfo[$config['mark']] = $config;
			}
				
			$this -> _CacheModel -> set($key, $configInfo);
			$this -> _CacheModel -> saveKeys($key, 'init');
		}
	
		return $configInfo;
	}
	
	/**
	 * 根据标识获取配置信息
	 * @param string $mark
	 * @return -2记录不存在
	 */
	public function getConfigInfo( $mark ) {
		$configList = $this -> getConfigList();
		if (!is_array($configList) || empty($configList))
			return -2;
	
		if (!isset($configList[$mark]) || !$configList[$mark])
			return -2;
	
		return $configList[$mark]['value'];
	}
	
}